/**
 * @description 券码
 */
import style from './styles/CouponCode.less';
import classnames from "classnames";
import React from 'react';
import copy from 'copy-to-clipboard';

import { Button, Toast } from 'wd-mobile';

import util from "commons/util";
const Fragment = React.Fragment;

class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            wait: false,
            fail: false
        }
    }
    
    render() {
        return (
            <div className={style.couponCode}>
                {
                    (this.props.cardType == 1 || this.props.cardType == 3 || this.props.cardType == 4) && <div className={style.couponCodeItem}>
                        <div className={style.couponCodeItemLeft}>
                            <span className={style.couponCodeItemTitle}>券码：</span>
                            <span className={style.couponCodeItemValue}>{this.props.cardValue}</span>
                        </div>
                        <div className={style.couponCodeItemCopy} onClick={() => {
                            this.copyCardValue();
                        }}>复制</div>
                    </div>
                }
                {
                    this.props.cardType == 3 && <div className={style.couponCodeItem}>
                        <div className={style.couponCodeItemLeft}>
                            <span className={style.couponCodeItemTitle}>密码：</span>
                            <span className={style.couponCodeItemValue}>{this.props.cardPwd}</span>
                        </div>
                        <div className={style.couponCodeItemCopy} onClick={() => {
                            this.copyCardPwd();
                        }}>复制</div>
                    </div>
                }
                {
                    this.props.cardType == 4 && <Button className={style.exchangeLink} onClick={()=>{
                        location.href = this.props.rechargeUrl;
                    }}>
                        立即兑换
                    </Button>
                }
            </div>
        )
    }

    // 复制券码
    copyCardValue() {
        copy(this.props.cardValue);
        Toast.info("券码已复制");
    }

    // 复制密码
    copyCardPwd() {
        copy(this.props.cardPwd);
        Toast.info("密码已复制");
    }
}
export default App;